from typing import List


class Solution:
    def topKFrequent(self, nums: List[int], k: int) -> List[int]:
        temp = []
        hashcount = dict()
        for i in range(len(nums)):
            if nums[i] not in hashcount:
                hashcount[nums[i]] = 1
            else:
                hashcount[nums[i]] += 1
        for key, value in hashcount.items():
            temp.append([key, value])
        temp.sort(key=lambda x: x[1], reverse=True)
        result = []
        for j in range(k):
            result.append(temp[j][0])
        return result


if __name__ == '__main__':
    t = [1,1,1,2,2,3]
    s = Solution()
    print(s.topKFrequent(t, 2))